#include "PopupUserMessage.hpp"

using namespace std;
using namespace Popup;

UserMessageWrapper::UserMessageWrapper(const Message *p_message)
: AbstractMessage(POPUP_MSG_TYPE_MESSAGE)
{
  AbstractMessage::deserialize(p_message);
}

bool UserMessageWrapper::onSend()
{
  bool _rc = payloadAddLongLong(THREAD, message.threadID);

  if (_rc) {
    payloadAddLongLong(ID, message.msgID);
  }

  if (_rc) {
    _rc = payloadAddLong(TARGETS, message.targets);
  }
  if (_rc) {
    payloadAddLong(SENDER, message.senderID);
  }
  if (_rc) {
    payloadAddString(TEXT, message.text);
  }
  if (_rc) {
    payloadAddString(TITLE, message.title);
  }
  if (_rc && message.URLs.size() > 0) {
      payloadAddString(URLS, message.URLs);
  }
  if (_rc && attachmentIDs.size() > 0) {
    payloadAddLongLong(ATTACHMENT_IDS, attachmentIDs);
  }

  return _rc;
}

bool UserMessageWrapper::onReceive()
{
  bool _rc = payloadGetLongLong(THREAD, threadID);

  if (_rc) {
    payloadGetLongLong(ID, msgID);
  }
  if (_rc) {
    _rc = payloadGetLong(TARGETS, targets);
  }
  if (_rc) {
    _rc = payloadGetLong(SENDER, senderID);
  }
  if (_rc) {
    payloadGetString(TEXT, text);
  }
  if (_rc) {
    payloadGetString(TITLE, title);
  }
  if (_rc) {
    payloadGetString(URLS, URLs);
  }
  if (_rc) {
    payloadGetLongLong(ATTACHMENT_IDS, attachmentIDs);
  }
  return _rc;
}
